package com.vipshop.compass.context;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringBeanLocator implements ApplicationContextAware {

	private static SpringBeanLocator singletonLocator;

	public static SpringBeanLocator getInstance() {
		if (singletonLocator == null) {
			singletonLocator = new SpringBeanLocator();
		}
		return singletonLocator;
	}

	public static void main(String args[]) {
		SpringBeanLocator.getInstance().getBean("jdbcTemplate");
	}

	private ApplicationContext applicationContext;

	public SpringBeanLocator() {
		super();
	}

	public Object getBean(String beanName) {
		return this.applicationContext.getBean(beanName);
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.applicationContext = applicationContext;
	}

}
